<?php
namespace app\admin\controller;
use think\Db;//导入数据库类 (DB类)
use think\Controller;
class Node extends Common
{


	//管理员设置
	public function index()
    {   
//         $subQuery= Db::view('Method')
//         ->buildSql();
//         $count=Db::table($subQuery."a")->count();
//         $pagesize='3';
//         $page_u=new \util\Page($count,$pagesize);
//         $page_u=$page_u->fpage();
//         $page=input('get.page');
//         $page=isset($page)?$page:"1";
        
    	$data=db('method')->paginate(3);
    	$page_u = $data->render();
     
    	$this->assign('data',$data);
        $this->assign('page',$page_u);
      return view('Jurisdiction/node');
        
    }
  public function del($id)
    {
      
        $data=db('method')->where('id',$id)->delete();
        if ($data>0) {
          $this->success('删除成功','admin/node/index');
        }else{
          $this->error('删除失败');
        }
    }

  public function edit($id)
    {
        $data=db('method')->where('id',$id)->find();
        $this->assign('data',$data);
        return view('Jurisdiction/nodeedit');     
   
    }

    public function doedit($id)
   {
       
    if (empty(input('name')&&input('controller')&&input('node'))) {
              $this->error('输入信息有误');
          }
          $status=input('post.status');
          $data = ['name' =>input('name'), 'controller' => input('controller'),'node' => input('node'),'status'=>$status];
          $rus=db('method')->where('id',$id)->update($data);
          if ($rus>0) {
              $this->success('修改成功','admin/node/index');
          }else{
              $this->error('错误');
          }
   }
    public function add()
    {
       
        return view('Jurisdiction/nodeadd');     
   
    }

    public function doadd()
    {
       
       if (empty(input('name')&&input('controller')&&input('node'))) {
              $this->error('输入信息有误');
      }
      $status=input('post.status');
        $data = ['name' =>input('name'), 'controller' => input('controller'),'node' => input('node'),'status'=>$status];
           $rus=db('method')->insert($data);
           if ($rus>0) {
              $this->success('新增成功','admin/node/index');
          }else{
              $this->error('新增失败');
          }
    }

}	
